<?php

try {
	
	date_default_timezone_set('Europe/Warsaw');
	
	error_reporting(E_ALL | E_STRICT);  
	ini_set('display_startup_errors', 1);  
	ini_set('display_errors', 1); 

	// Define path to application directory
	defined('APPLICATION_PATH')
	 || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));

	
	// Define application environment
	defined('APPLICATION_ENV')
	 || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
	
	set_include_path(
	 '.' . PATH_SEPARATOR .
	 './library/' . PATH_SEPARATOR .
	 './application/' . PATH_SEPARATOR .
	 './application/assistant/' . PATH_SEPARATOR .
	 './application/modules/' . PATH_SEPARATOR .
	 './application/models/' . PATH_SEPARATOR .
	 './application/models/generated' . get_include_path()
	);
	
	/** Zend_Application */
	require_once 'Zend/Application.php';

	//require_once 'application/Bootstrap.php';
	
	//create Router
		
//	$router = $ctrl->getRouter(); // domyślnie zwraca rewrite router
//	$router->addRoute(
//	'game',
//	new Zend_Controller_Router_Route(
//    	'wow/:gamename',
//		array(
//	        'controller' => 'game',
//	        'action'     => 'showone'
//    	)
//	));
	// Create application, bootstrap, and run
	$application = new Zend_Application(
		APPLICATION_ENV, './configs/application.ini'
	);

	$route = new Zend_Controller_Router_Route(
          'produkt/:gamename',
		array(
	        'controller' => 'index',
	        'action'     => 'showone'
    	)
      );
	$route2 = new Zend_Controller_Router_Route(
          'kategoria/:gamename',
		array(
	        'controller' => 'index',
	        'action'     => 'products'
    	)
      );
	
    $router = Zend_Controller_Front::getInstance()->getRouter();
    $router->addRoute('index', $route);
    
    $router->addRoute('kategoria', $route2);
    

	$application->bootstrap()
	 ->run();
	       
	 
} catch( Exception $e ) {
	Core_Logs::log( 'keyenew', 'log', '###START###' );
	Core_Logs::log( 'keyenew', 'log', 'ref: '   . $_SERVER['REMOTE_ADDR'] );
	Core_Logs::log( 'keyenew', 'log', 'url: '   . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
	Core_Logs::log( 'keyenew', 'log', 'msg: '   . $e->getMessage() );
	Core_Logs::log( 'keyenew', 'log', 'code: '  . $e->getCode() );
	Core_Logs::log( 'keyenew', 'log', 'file: '  . $e->getFile()) ;
	Core_Logs::log( 'keyenew', 'log', 'line: '  . $e->getLine() );
	Core_Logs::log( 'keyenew', 'log', 'trace: ' . $e->getTraceAsString() );
	Core_Logs::log( 'keyenew', 'log', '###END###' );

	//if( isSet( $_COOKIE['hadzia'] ) && $_COOKIE['hadzia'] == 'ryszard' ) {
		echo '<div style="color: red;"> <h1>FATAL ERROR</h1>';
			echo '<b>ref:</b> '.$_SERVER['REMOTE_ADDR'].'<hr />';
			echo '<b>url:</b> '.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'<hr />';
			echo '<b>error msg:</b> '.$e->getMessage().'<hr />';
			echo '<b>error code:</b> '.$e->getCode().'<hr />';
			echo '<b>error in file:</b> '.$e->getFile().'<hr />';
			echo '<b>error line:</b> '.$e->getLine().'<hr />';
			echo '<b>error trace:</b> '.$e->getTraceAsString().'';
		echo '</div>';
	//} else {
	//	header( 'location: http://www.keye.pl' );
	//}
}